import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
import {resolve} from "path"
// 自动导入antd组件
import AutoImport from 'unplugin-auto-import/vite'
import AntdResolver from 'unplugin-auto-import-antd'
// https://vitejs.dev/config/
export default defineConfig({
  css: {
    preprocessorOptions: {
      scss: {
        api: 'modern-compiler' // or "modern"
      }
    }
  },
  server: {
    host:"localhost",
    port: 3000,
    strictPort: true, //端口被占用直接退出
    open: true,
    hmr: true,//热更新
    proxy: {//设置代理
      '/api': {
        target: 'https://api.oioweb.cn/',// 后端接口
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
      },
    },
  },
  plugins: [react(), AutoImport({
    imports:['react','react-router-dom'],
    resolvers: [AntdResolver()]
  })],
  resolve: {
    alias: {
        // @ 替代为 src
      '@': resolve(__dirname, 'src')
    },
  },
})
